home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / driverss.zip / PKTSEND.ASM < prev    next >
Assembly Source File  |  1990-12-23  |  10KB  |  457 lines

  1. version    equ    1
  2.  
  3. ;  Russell Nelson, Clarkson University.  December 24, 1989
  4. ;  Copyright, 1989, Russell Nelson
  5.  
  6. ;   This program is free software; you can redistribute it and/or modify
  7. ;   it under the terms of the GNU General Public License as published by
  8. ;   the Free Software Foundation, version 1.
  9. ;
  10. ;   This program is distributed in the hope that it will be useful,
  11. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ;   GNU General Public License for more details.
  14. ;
  15. ;   You should have received a copy of the GNU General Public License
  16. ;   along with this program; if not, write to the Free Software
  17. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.     include    defs.asm
  20.  
  21. code    segment word public
  22.     assume    cs:code, ds:code
  23.  
  24.     org    2h
  25. phd_memsize    label    word
  26.  
  27.     org    80h
  28. phd_dioa    label    byte
  29.  
  30.     org    100h
  31. start:
  32.     jmp    start_1
  33. copyleft_msg    label    byte
  34.  db "Packet sender version ",'0'+majver,".",'0'+version," copyright 1990, Russell Nelson.",CR,LF
  35.  db "This program is free software; see the file COPYING for details.",CR,LF
  36.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  37. crlf_msg    db    CR,LF,'$'
  38.  
  39. int_pkt    macro
  40.     pushf
  41.     cli
  42.     call    their_isr
  43.     endm
  44.  
  45. their_isr    dd    ?
  46. packet_int_no    db    ?,?,?,?
  47. handle        dw    ?
  48. packet_flag    dw    0
  49. repeat_switch    db    ?
  50. quiet_switch    db    ?
  51. async_switch    db    ?
  52.  
  53. send_count    dw    ?,?
  54. pkt_count    dd    ?
  55.  
  56. async_iocb1    iocb    <0, 0, DONE>    ;Two iocbs
  57. async_iocb2    iocb    <0, 0, DONE>
  58.  
  59. signature    db    'PKT DRVR',0
  60. signature_len    equ    $-signature
  61.  
  62. no_signature_msg    db    "No packet driver at that address",'$'
  63. usage_msg    db    "usage: pktsend <packet_int_no> [-r [-q] | -n number] [-f filename | -l length | packet]",'$'
  64. sending_msg    label    byte
  65.     db    "Press space to re-send packet(s).  Any other key exits.",CR,LF,'$'
  66. repeat_msg    label    byte
  67.     db    "Sending repeat packets.  Any key exits.",CR,LF,'$'
  68. file_not_found    db    "File not found",'$'
  69. read_trouble    db    "Trouble reading the file",'$'
  70. non_number_msg    db    "Non-numeric input found",'$'
  71. mem_trashed_msg    db    CR,LF,"Found trashed memory at ",'$'
  72.  
  73. line_buffer    db    128 dup(?)
  74.  
  75. usage_error:
  76.     mov    dx,offset usage_msg
  77. error:
  78.     mov    ah,9
  79.     int    21h
  80.     int    20h
  81.  
  82. start_1:
  83.     mov    dx,offset copyleft_msg
  84.     mov    ah,9
  85.     int    21h
  86.  
  87.     mov    si,offset phd_dioa+1
  88.     cmp    byte ptr [si],CR    ;end of line?
  89.     je    usage_error
  90.  
  91.     mov    di,offset packet_int_no
  92.     call    get_number
  93.     mov    word ptr pkt_count,1
  94.     mov    word ptr pkt_count+2,0
  95.  
  96. another_switch:
  97.     call    skip_blanks
  98.  
  99.     mov    al,[si]            ;did the give the packet inline?
  100.     cmp    al,'-'            ;did they specify a switch?
  101.     jne    not_switch
  102.     cmp    byte ptr [si+1],'r'    ;did they specify '-r'?
  103.     je    got_repeat_switch
  104.     cmp    byte ptr [si+1],'q'    ;did they specify '-q'?
  105.     je    got_quiet_switch
  106.     cmp    byte ptr [si+1],'n'    ;did they specify '-n'?
  107.     je    got_number_switch
  108.     cmp    byte ptr [si+1],'l'    ;did they specify '-l'?
  109.     je    got_length_switch
  110.     cmp    byte ptr [si+1],'f'    ;did they specify '-f'?
  111.     je    start_file
  112.     cmp    byte ptr [si+1],'a'    ;did they specify '-a'?
  113.     je    got_async_switch
  114.     jmp    usage_error        ;no, must be an error.
  115. got_repeat_switch:
  116.     mov    repeat_switch,1
  117.     add    si,2
  118.     jmp    another_switch
  119. got_quiet_switch:
  120.     mov    quiet_switch,1
  121.     add    si,2
  122.     jmp    another_switch
  123. got_number_switch:
  124.     add    si,2
  125.     mov    di,offset pkt_count
  126.     call    get_number
  127.     jmp    another_switch
  128. got_length_switch:
  129.     add    si,2
  130.     mov    di,offset send_count
  131.     call    get_number
  132.     mov    di,offset our_buffer
  133.     add    di,send_count
  134.     jmp    start_gotit
  135. got_async_switch:
  136.     mov    async_switch,1
  137.     add    si,2
  138.     jmp    another_switch
  139. not_switch:
  140.     jmp    start_inline        ;yes.
  141.  
  142. start_file:
  143.     add    si,2
  144.     call    skip_blanks
  145.     mov    dx,si            ;remember where the filename starts.
  146. start_3:
  147.     lodsb
  148.     cmp    al,' '
  149.     je    start_4
  150.     cmp    al,CR
  151.     jne    start_3
  152. start_4:
  153.     dec    si
  154.     mov    byte ptr [si],0
  155.  
  156. ;read the packet bytes from the named file.
  157.  
  158.     mov    ax,3d00h        ;open for reading.
  159.     int    21h
  160.     jnc    file_found
  161.     mov    dx,offset file_not_found
  162.     jmp    error
  163.  
  164. file_found:
  165.     mov    handle,ax
  166.     mov    di,offset our_buffer
  167. start_line:
  168.     mov    si,offset line_buffer
  169. again_line:
  170.     mov    ah,3fh            ;read a single character.
  171.     mov    bx,handle
  172.     mov    cx,1
  173.     mov    dx,si
  174.     int    21h
  175.     jnc    no_trouble
  176.     mov    dx,offset read_trouble
  177.     jmp    error
  178.  
  179. no_trouble:
  180.     cmp    ax,1            ;did we actually read one?
  181.     je    not_eof
  182.     cmp    si,offset line_buffer    ;did we read anything this time?
  183.     je    start_file_eof        ;no, it's really eof this time.
  184.     mov    [si],byte ptr CR    ;add an extra CR, just in case.
  185.     jmp    short done_reading
  186. not_eof:
  187.     lodsb                ;get the character we just read.
  188.     cmp    al,LF            ;got the LF?
  189.     jne    again_line        ;no, read again.
  190.  
  191. done_reading:
  192.     mov    si,offset line_buffer
  193. again_chars:
  194.     call    get_number
  195.     jnc    got_a_number
  196.     mov    dx,offset non_number_msg
  197.     jmp    error
  198. got_a_number:
  199.     inc    di
  200.     call    skip_blanks
  201.     cmp    al,CR
  202.     jne    again_chars        ;keep going to the end.
  203.  
  204.     jmp    start_line
  205.  
  206. start_file_eof:
  207.     mov    ah,3eh            ;close the file.
  208.     mov    bx,handle
  209.     int    21h
  210.     jmp    short start_gotit
  211.  
  212. start_inline:
  213. ;read the packet bytes off the command line.
  214.     mov    di,offset our_buffer-1
  215. start_2:
  216.     inc    di            ;pre-increment
  217.     call    get_number        ;get a byte.
  218.     jnc    start_2            ;keep going to the end.
  219.  
  220. start_gotit:
  221.  
  222.     sub    di,offset our_buffer
  223.     mov    send_count,di
  224.  
  225.     mov    sp,offset start        ;now that we're finished with
  226.                     ;the parameters, put our stack there.
  227.  
  228.     mov    di,offset our_buffer + GIANT * 2
  229.     inc    di
  230.     and    di,not 1
  231.     push    cs
  232.     pop    es
  233. init_memory:
  234.     mov    ax,055aah        ;initialize a segment to 055aah.
  235.     mov    cx,di
  236.     neg    cx
  237.     shr    cx,1
  238.     stosw
  239.     sub    cx,2
  240.     rep    stosw
  241.     mov    ax,es
  242.     add    ax,1000h
  243.     mov    es,ax
  244.     add    ax,1000h
  245.     cmp    ax,phd_memsize        ;don't go past the end of memory.
  246.     jbe    init_memory
  247.  
  248.     mov    ah,35h            ;get their packet interrupt.
  249.     mov    al,packet_int_no
  250.     int    21h
  251.     mov    their_isr.offs,bx
  252.     mov    their_isr.segm,es
  253.  
  254.     lea    di,3[bx]
  255.     mov    si,offset signature
  256.     mov    cx,signature_len
  257.     repe    cmpsb
  258.     je    signature_ok
  259.     jmp    no_signature_err
  260. signature_ok:
  261.  
  262.     push    ds
  263.     mov    ax,1ffh            ;driver_info
  264.     int_pkt
  265.     pop    ds
  266.     call    fatal_error
  267.  
  268.     mov    ah,2            ;access all packets.
  269.     mov    al,ch            ;their class from driver_info().
  270.     mov    bx,dx            ;their type from driver_info().
  271.     mov    dl,cl            ;their number from driver_info().
  272.     mov    cx,0            ;type length of zero.
  273.     push    cs            ;es:di -> our receiver.
  274.     pop    es
  275.     mov    di,offset our_recv
  276.     int_pkt
  277.     call    fatal_error
  278.     mov    handle,ax
  279.  
  280.     cmp    repeat_switch,0
  281.     je    load_count
  282.     mov    dx,offset repeat_msg
  283.     mov    ah,9
  284.     int    21h
  285. load_count:
  286.     mov    ax,word ptr pkt_count
  287.     mov    dx,word ptr pkt_count+2
  288.  
  289. send_again:
  290.     push    ax
  291.     push    dx
  292.     mov    ah,4            ;send_pkt
  293.     mov    si,offset our_buffer    ;ds:si -> buffer.
  294.     mov    cx,send_count
  295.     cmp    async_switch,0        ;async?
  296.     je    send_pkt        ;no
  297.     mov    ah,12            ;as_send_pkt
  298. find_iocb:                ;find a free iocb
  299.     mov    di,offset async_iocb1    ;try first
  300.     test    [di].flags,DONE        ;free?
  301.     jnz    got_iocb        ;yes
  302.     mov    di,offset async_iocb2    ;no, try second
  303.     test    [di].flags,DONE        ;free?
  304.     jz    find_iocb        ;no, try first again
  305. got_iocb:                ;set up iocb
  306.     mov    word ptr [di].buffer,si
  307.     mov    word ptr [di].buffer+2,ds
  308.     mov    es,word ptr [di].buffer+2
  309.     mov    [di].len,cx
  310.     mov    [di].flags,0        ;clear flags (i.e. DONE bit)
  311. send_pkt:
  312.     int_pkt
  313.     jnc    pkt_sent_ok
  314.     jmp    pkt_sent_bad
  315. pkt_sent_ok:
  316.     pop    dx
  317.     pop    ax
  318.     sub    ax,1            ;decrement low word
  319.     sbb    dx,0            ;decrement high word
  320.     mov    bx,ax            ;check if we reached zero
  321.     or    bx,dx
  322.     jne    send_again        ;we didn't
  323.  
  324. check_repeat:
  325.     cmp    repeat_switch,0        ;did they ask for repeat sending?
  326.     jne    send_repeat
  327.  
  328.     mov    dx,offset sending_msg
  329.     mov    ah,9
  330.     int    21h
  331.  
  332.     mov    ah,0            ;read a key.
  333.     int    16h
  334.     cmp    al,' '
  335.     je    load_count        ;a space -- send again.
  336.     jmp    short send_done
  337.  
  338. send_repeat:
  339.     cmp    quiet_switch,0
  340.     jne    chrout_done
  341.     mov    al,'T'
  342.     call    chrout
  343.  
  344. chrout_done:
  345.     cmp    packet_flag,0
  346.     je    no_packet
  347.  
  348.     mov    al,'R'
  349.     call    chrout
  350.  
  351.     mov    packet_flag,0
  352.  
  353. no_packet:
  354.     mov    ah,1            ;check for any key.
  355.     int    16h
  356.     jne    got_key
  357.     jmp    load_count        ;no key -- keep waiting.
  358.  
  359. got_key:
  360.     mov    ah,0            ;read a key.
  361.     int    16h
  362.  
  363. send_done:
  364.     mov    ah,3            ;release the handle.
  365.     mov    bx,handle
  366.     int_pkt
  367.     call    fatal_error
  368.  
  369.     mov    di,offset our_buffer + GIANT * 2
  370.     inc    di
  371.     and    di,not 1
  372.     push    cs
  373.     pop    es
  374. compare_memory:
  375.     mov    ax,055aah        ;compare a segment against 055aah.
  376.     mov    cx,di
  377.     neg    cx
  378.     shr    cx,1
  379.     scasw
  380.     jne    memory_bad
  381.     sub    cx,2
  382.     repe    scasw
  383.     jne    memory_bad
  384.     mov    ax,es
  385.     add    ax,1000h
  386.     mov    es,ax
  387.     add    ax,1000h
  388.     cmp    ax,phd_memsize        ;don't go past the end of memory.
  389.     jbe    compare_memory
  390.  
  391.     int    20h
  392. pkt_sent_bad:
  393.     call    print_error
  394.  
  395.     mov    ah,3            ;release the handle.
  396.     mov    bx,handle
  397.     int_pkt
  398.     call    fatal_error
  399.  
  400.     int    20h
  401.  
  402. memory_bad:
  403.     mov    dx,offset mem_trashed_msg
  404.     mov    ah,9
  405.     int    21h
  406.     mov    ax,es
  407.     call    wordout
  408.     mov    al,':'
  409.     call    chrout
  410.     mov    ax,di
  411.     dec    ax
  412.     call    wordout
  413.     mov    dx,offset crlf_msg
  414.     mov    ah,9
  415.     int    21h
  416.     int    20h
  417.  
  418. no_signature_err:
  419.     mov    dx,offset no_signature_msg
  420.     mov    ah,9
  421.     int    21h
  422.     int    20h
  423.  
  424.  
  425. our_recv:
  426.     or    ax,ax            ;first or second call?
  427.     jne    our_recv_1        ;second -- we ignore the packet
  428.     cmp    cs:packet_flag,0    ;Do we already have one?
  429.     jne    our_recv_2        ;yes - return zero.
  430.     push    cs
  431.     pop    es
  432.     mov    di,offset our_buffer + GIANT
  433.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  434. our_recv_2:
  435.     xor    di,di
  436.     mov    es,ax
  437.     mov    cx,0
  438.     loop    $
  439.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  440. our_recv_1:
  441.     inc    cs:packet_flag
  442.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  443.  
  444.  
  445.     include    pkterr.asm
  446.     include    getnum.asm
  447.     include    getdig.asm
  448.     include    skipblk.asm
  449.     include    chrout.asm
  450.     include    digout.asm
  451.  
  452. our_buffer    label    byte
  453.  
  454. code    ends
  455.  
  456.     end    start
  457.